package com.luu.game.service.impl;

import com.luu.game.data.dto.CombotInfoDTO;
import com.luu.game.data.dto.ElfInfoDTO;
import com.luu.game.data.dto.SkillInfoDTO;
import com.luu.game.service.BattleService;
import com.luu.game.service.LevelExpService;
import com.luu.game.service.SkillService;
import com.luu.game.service.logic.combat.Combat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BattleServiceImpl implements BattleService {

    @Autowired
    private SkillService skillService;
    @Autowired
    private LevelExpService levelExpService;

    /**
     * 攻击
     * @param attack 攻击方
     * @param defend 防守方
     * @return
     */
    @Override
    public CombotInfoDTO elfAtc(ElfInfoDTO attack, ElfInfoDTO defend) {
        final SkillInfoDTO skillInfo = skillService.findById(attack.getSkillId());
        // 计算伤害
        CombotInfoDTO returnDTO = Combat.combatCountForAtc(attack, defend, skillInfo);

        // 战斗结束，增加经验方
        if (returnDTO.isOver()){
            final Double baseExp = levelExpService.countCombatExp(defend);
            levelExpService.upLevel(attack.getId(),baseExp);
        }

        return returnDTO;
    }
}
